package com.gaoxin.api.service.selectcourse;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.gaoxin.api.dao.selectcourse.SelectCourseMapper;
import com.gaoxin.api.entity.selcourseentity.SelectCourse;
@Service
public class SelectCourseService {
	@Autowired
	private SelectCourseMapper selectCourseMapper;
	/**
	 * 查询选课时间段
	 * @return
	 */
	public SelectCourse findBTimeAndETime()throws Exception{
		return selectCourseMapper.findBTimeAndETime();
	}
	/**
	 * 查询某个学生当前所有的可选课程信息
	 * @param stuNumber
	 * @return
	 */
	public List<SelectCourse> findAllSelectCourse(String stuNumber)throws Exception{
		return selectCourseMapper.findAllSelectCourse(stuNumber);
	}
	/**
	 * 模糊查询某个学生当前所有的可选课程信息
	 * @param stuNumber
	 * @param courseName
	 * @return
	 */
	public List<SelectCourse> findLikeSelectCourse(String stuNumber,String courseName){
		return selectCourseMapper.findLikeSelectCourse(stuNumber, courseName);
	}
	/**
	 * 根据课程id查询所选课程具体信息
	 * @param courseId
	 * @param teacherId
	 * @param classroomId
	 * @return
	 * @throws Exception
	 */
	public List<SelectCourse> queryCourseInfo(String courseId ,String teacherId,String classroomId,String id)throws Exception{
		return selectCourseMapper.queryCourseInfo(courseId,teacherId,classroomId,id);
	}
	/**
	 * 查询某门课程所能选的总人数
	 * @param teacherId
	 * @param courseId
	 * @param classroomId
	 * @return
	 * @throws Exception
	 */
	public int queryTotalNumber(String teacherId,String courseId,String classroomId,String id) throws Exception{
		return selectCourseMapper.queryTotalNumber(courseId, teacherId,classroomId,id);
	}
	/**
	 * 查询某门课程当前已选人数
	 * @param courseId
	 * @param teacherId
	 * @param classroomId
	 * @return
	 * @throws Exception
	 */
	public int querySelectedNumber(String courseId ,String teacherId,String classroomId,String id)throws Exception{
		return selectCourseMapper.querySelectedNumber(courseId, teacherId,classroomId,id);
	}
	/**
	 * 保存学生选课信息
	 * @param courseId
	 * @param teacherId
	 * @param classroomId
	 * @param stuNumber
	 * @return
	 */
	@Transactional
	public int saveStuSelctionCourse(String courseId ,String teacherId,String classroomId,String stuNumber,String id)throws Exception{
		return selectCourseMapper.saveStuSelctionCourse(courseId, teacherId, classroomId, stuNumber,id);
	}
	/**
	 * 删除已选课程
	 * @param selectCourse
	 * @return
	 */
	@Transactional
	public int deleteStuSelctionCourse(String courseId ,String teacherId,String classroomId,String stuNumber,String id)throws Exception{
		SelectCourse selectCourse = new SelectCourse();
		selectCourse.setCourseId(courseId);
		selectCourse.setTeacherId(teacherId);
		selectCourse.setClassroomId(classroomId);
		selectCourse.setStuNumber(stuNumber);
		selectCourse.setId(id);
		return selectCourseMapper.deleteStuSelctionCourse(selectCourse);
	}
	/**
	 * 查询学生的所选课程信息
	 * @param selectCourse
	 * @return
	 * 
	 */
	public List<SelectCourse> findStuSelectedCourse(String stuNumber)throws Exception{//String courseId ,String teacherId,String classroomId,
		SelectCourse selectCourse = new SelectCourse();
//		selectCourse.setCourseId(courseId);
//		selectCourse.setTeacherId(teacherId);
//		selectCourse.setClassroomId(classroomId);
		selectCourse.setStuNumber(stuNumber);
		return selectCourseMapper.findStuSelectedCourse(selectCourse);
	}
	public int findMaxCourse () {
		return 0;
	}
	/**
	 * 查询学生已选课程门数
	 * @param selectCourse
	 * @returnN]
	 */
	public int findStudentCourseNumber(String stuNumber) {
		return selectCourseMapper.findStudentCourseNumber(stuNumber);
	}
}
